home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 14
/
Mac Magazin and MacEasy Magazine CD - Issue 14.iso
/
Wissenschaft & Technik
/
Caveman Sound
/
sndtest.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-11
|
5KB
|
146 lines
/*****************************************************************************
* FILE: sndtest.c
* AUTHOR: David Hay
* CREATED: March 9, 1995
* DESCRIPTION: Test program and tutorial for using the Caveman Sound System.
*
* Copyright © 1995 David Hay
*
* Permission to use, copy, and distribute this software and its documentation
* for any purpose is hereby granted without fee, provided that (i) the above
* copyright notices and this permission notice appear in all copies of the
* software and related documentation, and (ii) the names of David Hay and
* Caveman Creations may not be used in any advertising or publicity relating
* to the software without the specific, prior written permission of David Hay
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
* IMPLIED OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
* DAVID HAY OR CAVEMAN CREATIONS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
* POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*****************************************************************************/
#ifndef __SOUND__
#include <Sound.h>
#endif
#ifndef __CMSOUNDSYSTEM__
#include "CMSoundSystem.h"
#endif
#define kNumChannels 1 /* The number of sound channels to open */
/* Standard Mac Toolbox initialization */
static void
InitMacintosh( void )
{
MaxApplZone();
InitGraf(&qd.thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
}
void main( void )
{
WindowPtr win;
short ii;
Str255 name;
Handle icon;
short sndRef;
OSErr err;
InitMacintosh();
/* First you must initialize the sound system by specifying the
** number of channels you wish to use.
**/
err = CMSInitSound( kNumChannels );
/* After initialization, each channel must be opened for use.
** These can be opened individually with CMSOpenChannel() or
** you may open them all, as we have done here, with a call
** to CMSOpenAllChannels().
**/
if ( err == noErr ) err = CMSOpenAllChannels();
/* First let's just play a sound resource. This behaves almost
** identically to SndPlay(). You specify the resource number,
** the channel to play the sound on (sound channels start at 0)
** and whether the sound should be played asynchronously.
**/
if ( err == noErr ) err = CMSPlaySoundResource( 128, 0, true );
/* Since we played the last sound asynchronously, we want to
** find out when it stops so we can do other stuff. To do
** this we use the CMSGetSoundPlaying() routine. This returns
** the sound reference number of the currently playing sound,
** kSoundResource or kNoSound in the sndRef paramater. I
** could have used the routine CMSWaitForSilence() here, but
** very often the sound was played asynchronously so you could
** do other stuff while the sound is playing. Plus I wanted to
** show how the CMSGetSoundPlaying() function worked. ;-)
**/
while ( err == noErr )
{
err = CMSGetSoundPlaying( 0, &sndRef );
if ( sndRef == kNoSound )
break;
}
/* We call CMSIdleSoundTask() now to unlock the sound handle
** that we played with CMSPlaySoundResource(). This allows it
** to be purged if necessary. If we had called CMSStopSound()
** this would have been done for us automatically. This is useful
**/
CMSIdleSoundTask();
/* Now let's play some music. First call CMSLoadMusic() to
** load the music blocks into memory and register them with
** the sound system.
**/
if ( err == noErr ) err = CMSLoadMusic( 128 );
if ( err == noErr )
{
/* Start the music going with CMSPlayMusic(). Here we indicate
** that the music should be played on sound channel 0. This
** will play the music asynchronously. If a loop has been
** defined in the 'MUSL' resource, then the music will loop
** until it is stopped with a call to CMSStopSound() or another
** sound is played on the same channel.
**/
err = CMSPlayMusic( 0 );
while ( err == noErr )
{
err = CMSGetSoundPlaying( 0, &sndRef );
if ( sndRef < 1 )
break;
}
while ( !Button() && err == noErr )
{}
}
if ( err == noErr ) CMSStopSound( 0 );
/* We're finished with the sound system, so call CMSDisposeSound()
** to close and free the sound channels and any sounds registered
** with the sound system.
**/
CMSDisposeSound();
FlushEvents( everyEvent, 0 );
if ( err != noErr ) SysBeep( 10 );
}